package com.ruoyi.project.system.grades.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.grades.domain.ClassGrades;
import com.ruoyi.project.system.grades.service.IClassGradesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 班级Controller
 * 
 * @author ruoyi
 * @date 2021-04-14
 */
@Controller
@RequestMapping("/system/grades")
public class ClassGradesController extends BaseController
{
    private String prefix = "system/grades";

    @Autowired
    private IClassGradesService classGradesService;

    @RequiresPermissions("system:grades:view")
    @GetMapping()
    public String grades()
    {
        return prefix + "/grades";
    }

    /**
     * 查询班级列表
     */
    @RequiresPermissions("system:grades:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClassGrades classGrades)
    {
        startPage();
        List<ClassGrades> list = classGradesService.selectClassGradesList(classGrades);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @RequiresPermissions("system:grades:export")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClassGrades classGrades)
    {
        List<ClassGrades> list = classGradesService.selectClassGradesList(classGrades);
        ExcelUtil<ClassGrades> util = new ExcelUtil<ClassGrades>(ClassGrades.class);
        return util.exportExcel(list, "grades");
    }

    /**
     * 新增班级
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存班级
     */
    @RequiresPermissions("system:grades:add")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClassGrades classGrades)
    {
        return toAjax(classGradesService.insertClassGrades(classGrades));
    }

    /**
     * 修改班级
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClassGrades classGrades = classGradesService.selectClassGradesById(id);
        mmap.put("classGrades", classGrades);
        return prefix + "/edit";
    }

    /**
     * 修改保存班级
     */
    @RequiresPermissions("system:grades:edit")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClassGrades classGrades)
    {
        return toAjax(classGradesService.updateClassGrades(classGrades));
    }

    /**
     * 删除班级
     */
    @RequiresPermissions("system:grades:remove")
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(classGradesService.deleteClassGradesByIds(ids));
    }
}
